﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;

namespace WebApi
{
    public class DBHelper
    {
        static string str_conn = "Persist Security Info=False;User ID=sa;pwd=111;Initial Catalog=test;Data Source=(local)";
        public DBHelper()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public static DataSet Query(string sql)
        {
            SqlConnection conn = new SqlConnection(str_conn);
            DataSet ds = new DataSet();
            SqlDataAdapter sqlData = new SqlDataAdapter(sql, conn);
            sqlData.Fill(ds);
            return ds;
        }


        public static bool Exec(string sql)
        {
            SqlConnection conn = new SqlConnection(str_conn);
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            int i = cmd.ExecuteNonQuery();
            conn.Close();
            return i > 0;
        }

    }
}
